Skip to content

Add credential handling to UserClient and ToolClient#534

Open
dannon wants to merge 4 commits intogalaxyproject:mainfrom
dannon:credential-handling
Open

Add credential handling to UserClient and ToolClient#534
dannon wants to merge 4 commits intogalaxyproject:mainfrom
dannon:credential-handling

Conversation

@dannon
Copy link
Copy Markdown
Member

@dannon dannon commented Apr 9, 2026

Summary

  • Add get_credentials, create_credentials, select_credential_group, and get_credentials_for_tool methods to UserClient wrapping Galaxy's /api/users/{id}/credentials endpoints
  • Add credentials_context parameter to ToolClient.run_tool() for passing stored credentials when executing tools that require them
  • get_credentials_for_tool is a convenience method that builds the credentials_context list from stored credentials, ready to pass directly to run_tool()

Test plan

  • Integration tests added for all credential methods (gated on release_25.1)
  • Verify create_credentials + select_credential_group + get_credentials_for_tool + run_tool(credentials_context=...) workflow against a Galaxy instance with credential support
  • ruff check and ruff format pass

dannon added 4 commits April 8, 2026 21:57
Add get_credentials, create_credentials, and get_credentials_for_tool
methods to UserClient for managing stored credentials (API keys, etc.)
via Galaxy's credentials API. Also add credentials_context parameter to
ToolClient.run_tool() so credentials can be passed through when
executing tools that require them.
The get_credentials_for_tool helper was using wrong field names from
the Galaxy API response -- service_name/service_version instead of
name/version, and current_group (an object) instead of
current_group_id (an ID) with a groups list lookup. Verified against
Galaxy's schema in credentials.py. Also widened run_tool payload type
annotation and added integration tests for the credential methods.
Galaxy doesn't auto-set current_group_id when credentials are created,
so the get_credentials_for_tool helper was broken out of the box. Add
select_credential_group wrapping PUT /api/users/{id}/credentials so
callers can activate a group after creation.

Also fix truthiness checks to use 'is not None' instead of truthy
evaluation, clarify create_credentials return docstring, and update
tests to call select_credential_group before get_credentials_for_tool.
…ssing credential tools

Ruff format with default line-length was reformatting existing code
that black with line-length=120 left alone, causing lint failures.
Reverted all formatting-only changes to existing code.

Bumped test version gate from release_25.0 to release_25.1 since
the credentials API doesn't exist in 25.0. The create/get_for_tool
tests now use a real tool ID and gracefully skip when the tool doesn't
have credential definitions (which is the case for standard test tools).
)
except ConnectionError as e:
if "does not require any credentials" in str(e) or "not defined" in str(e):
self.skipTest("Test tool does not have credential definitions")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the following tests are always skipped because random_lines1 doesn't require credentials, can we use secret_tool instead (which is used in Galaxy's test/integration/test_credentials.py)?

) -> None:
"""
Select the active credential group for a set of user credentials.
This must be called after ``create_credentials()`` before the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This must be called after ``create_credentials()`` before the
This must be called after credentials have been created but before the

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants